<?php
/**
 * 消费订单提交接口
 */
namespace App\Controller;

use Think\Controller;

class SaleController extends Controller {

    public  $page_num = 10;
    private $m_card_sale;
    private $m_sale_good;

	public function _initialize() {
        $this->m_card_sale = D("Sale/CardSale");
	    $this->m_sale_good = D("Sale/SaleGood");
	}
    /**
     *  消费记录
     */
    public function lists() {
        $page_num = I("post.page_num",1);
        $card_number = I("post.card_number");
        if(empty($card_number)){
            $this->errorReturn("请先输入卡号！");
        }
        $page_num = $page_num<0?1:$page_num;
        $where = ["s.card_number"=>$card_number];
        $list = $this->m_card_sale->get_list($where,"s.create_time DESC",($page_num-1)*$this->page_num, $this->page_num);
        $this->successReturn($list);
    }


    /**
     * 消费记录详情
     */
    public function detail() {
        $detail_id = I("post.detail_id");
        if(empty($detail_id)){
            $this->errorReturn("请输入消费记录详情ID");
        }
        $where = ['s.id'=>$detail_id];
        $item = $this->m_card_sale->get_one($where);
        if(empty($item)){
            $this->errorReturn("消费记录不存在！");
        }else{
            $this->successReturn($item);
        }
    }




}

